<%-- 
    Document   : addStaff
    Created on : Jun 29, 2012, 4:33:40 PM
    Author     : Home
--%>

<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="dbTool.myConnection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="dbTool.functions"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>add Student Page</title>
    </head>
    <body>
        <%            
            String dealerID = request.getParameter("dealerID");
            String sAcc = request.getParameter("sAcc").trim();
            String sName = request.getParameter("sName");
            int role = Integer.parseInt(request.getParameter("role"));
            int gender = Integer.parseInt(request.getParameter("gender"));
            String birthday = request.getParameter("bday");
            String address = request.getParameter("address");
            String phone = request.getParameter("phone");
            String mail = request.getParameter("mail");
            int status = Integer.parseInt(request.getParameter("status"));
            
            
            String sID = request.getParameter("id");
            if (sID == null) {
                functions f = new functions();
                int i = f.addStaff(sAcc, dealerID, sName, role, gender, birthday, address, phone, mail, status);                
                if (i != 0) {
                    out.print("<script>alert('Add succsessfull. Staff "+sAcc+"!');window.location='staff.jsp';</script>");
                } else {
                    out.print("<script>alert('Error.Can not add newStaff!');window.location= 'staff.jsp';</script> ");
                }
                
            } else {
                int staffID = Integer.parseInt(request.getParameter("id").toString());
                functions f = new functions();
                int i = f.updateStaff(dealerID, sName, role, gender, birthday, address, phone, mail, status, staffID);                
                if (i != 0) {
                    out.print("<script>alert('Update succsessfull. Staff: "+sAcc+"!');window.location='staff.jsp?id="+sID+"';</script>");
                } else {
                    out.print("<script>alert('Error.Can not update Staff "+sAcc+"!');window.location= 'staff.jsp?id="+sID+"';</script> ");
                }
            }
            
        %>
    </body>
</html>
